<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统登录</title>
    <link rel="stylesheet" href="css/index.css">
    <style >
        .box-card{
            width: 480px;
            height: 300px;
            margin: 200px auto;/*居中显示*/
        }
    </style>
</head>
<body>
    <div id="app">
        <el-card class="box-card">
            <span style="color:red">{{error}}</span>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="账号">
                    <el-input v-model="form.username" placeholder="请输入账号"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input type="password" v-model="form.password" placeholder="请输入密码">
                    </el-input>
                </el-form-item>
                <el-form-item label="记住我">
                    <el-checkbox  v-model="form.rememberMe">
                    </el-checkbox>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login">登录</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
    <script src="js/vue.js"></script>
    <script src="js/index.js"></script>
    <script src="js/axios.min.js"></script>
    <script src="js/qs.min.js"></script>
    <script>
        new Vue({
            el:"#app",
            data(){
                return {
                    form:{  //绑定表单数据
                        username:'',
                        password:'',
                        rememberMe:false //记住我
                    },
                    error:'' //错误信息
                }
            },
            methods:{
                login(){
                    console.log(this.form.username+"---"+this.form.password);
                    //将form对象转换为username=xxx&password=xxx的格式发送给后台doLogin处理
                    axios.post("/doLogin",Qs.stringify(this.form))
                        .then(value => {
                            console.log(value);
                            //判断如果返回了用户名，就跳转主页面
                            if(value.data.username){
                                location.href = "index.html";
                            }else{
                                this.error = value.data;
                            }
                        })
                }
            }
        });
    </script>
</body>
</html>